package com.yc.jpyy.mobile.controller;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.BizDao;
import com.yc.jpyy.mobile.service.BizService;

@Controller
@RequestMapping(value = "/student")
public class GetFirstPageDatas extends BaseController {
	
	@Autowired
	private BizService bizService;
	@Autowired
	private BizDao bizDao;

	/**
	 * 获取首页数据
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getFirstPageDatas", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getFirstPageDatas(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {
			// 用户Id
			String userId = request.getParameter("userId");
			// 学员Id
			String studentId = request.getParameter("studentId");
			// 科目Id
			String subjectId = request.getParameter("subjectId");
			// 学驾类型
			String driverType = request.getParameter("driverType");
		 
			if(userId != null && !userId.isEmpty()
					&& studentId != null && !studentId.isEmpty() 
					&& subjectId != null && !subjectId.isEmpty()
					&& driverType != null && !driverType.isEmpty())
			{
				Map<String, Object> valMap = new HashMap<String, Object>();	
				valMap.put("studentId", studentId);
				valMap.put("subjectId", subjectId);
				valMap.put("driverType", driverType);
				valMap.put("userId", userId);
				//获取首页数据
				response = bizService.selectPageDatas(valMap,studentId,subjectId,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("学员ID、科目类型不能为空...");
			}
		} catch (Exception e) {
			System.out.println("getFirstPageDatas:"+ e.toString());
			response.setReturnMsg(1,"获取数据失败！");
		} finally {
			return response.toJSON();
		}
	}
	
}
